#include <stdio.h>
#include "utils.h"
#include "supp.h"






static int sub_overflow(unsigned int a, unsigned int b, unsigned int result)
{
	return ((NEG(a) && NEG(b) && POS(result)) 
		|| (POS(a) && POS(b) && NEG(result)));
}



static int add_overflow(unsigned int a, unsigned int b, unsigned int result)
{
	return ((NEG(a) && POS(b) && POS(result))
		|| (POS(a) && NEG(b) && NEG(result)));
}


/* these functions are used in ADDS, ADCS, CMN instruction*/
/*set_add_carry(), set_add_overflow()*/
void set_add_carry(ARMProcState* state,unsigned int a, unsigned int b, unsigned int result)
{
	unsigned int val = 0;
	val = ((NEG(a) && NEG(b)) ||
		(NEG (a) && POS (result)) || (NEG (b) && POS (result)));

	state->CFlag = val;
}

void set_add_overflow(ARMProcState *state, unsigned int a, unsigned int b, unsigned int result)
{
	unsigned int val = 0;
	val = add_overflow(a,b,result);

	state->VFlag = val;


}

/* these functions are used in SUBS, CMP, SBCS, RSCS, RSBS instruction */
/*set_sub_carry(),  set_sub_overflow() */

void set_sub_carry (ARMProcState *state, unsigned int a, unsigned int b, unsigned int result)
{
	unsigned int val = 0;

	val = ((NEG(a) && POS(b)) ||
		(NEG(a) && POS(result)) || (POS(b) && POS(result)));

}

void set_sub_overflow(ARMProcState *state, unsigned int a, unsigned int b, unsigned int result)
{

	unsigned int val = 0;

	val = ((NEG(a) && POS(b)) ||
		(NEG(a) && POS(result)) || (POS(b) && POS(result)));
}

